package com.hsq.ndmall.wx.controller;

import com.hsq.ndmall.common.config.login.LoginUser;
import com.hsq.ndmall.common.holder.LoginUserHolder;
import com.hsq.ndmall.common.utils.R;
import com.hsq.ndmall.wx.from.CheckoutFrom;
import com.hsq.ndmall.wx.from.FastAddFrom;
import com.hsq.ndmall.wx.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author 黄四清
 * @version 1.0.0
 * @ClassName CartController.java
 * @Description TODO
 * @createTime 2021年08月19日 15:39:00
 */
@RestController
@RequestMapping("/wx/cart")
public class CartController {

    @Autowired
    CartService cartService;

    @PostMapping("/fastadd")
    public R fastAdd(@LoginUser Integer id, @RequestBody FastAddFrom fastAdd) {
        Map map = cartService.isFastAdd(id, fastAdd);
        return R.ok(map);
    }

    @GetMapping("/checkout")
    public R checkout(@LoginUser Integer id, CheckoutFrom checkoutFrom) {
        Map map = cartService.isCheckout(id, checkoutFrom);
        return R.ok().put("data", map);
    }

    @GetMapping("/index")
    public R selectIndex() {
        Map map = cartService.homeIndex();
        return R.ok().put("data", map);
    }
}
